const KoaRouter = require('@koa/router')
const userController = require('../controller/user.controller')
const { verifUser, handlePassword } = require('../middleware/user.middleware')
const { remove, update, get, getList } = require('../controller/user.controller')
const { verifAuth } = require('../middleware/login.middleware')

// 1.创建路由对象
const userRouter = new KoaRouter({ prefix: '/users' })
// 2.定义路由映射
// 用户注册接口(增)
userRouter.post('/', verifUser, handlePassword, userController.create)
// 为用户提供头像(查看用户头像)
userRouter.get('/avatar/:userId', verifAuth, userController.showAvatarImage)

// 查
userRouter.get('/:id', verifAuth, get)

// 列表(分页查询)
userRouter.post('/list', verifAuth, getList)
// 改
userRouter.post('/:id', verifAuth, update)
// // 删
userRouter.delete('/:id', verifAuth, remove)

module.exports = userRouter